package com.spzx.channel.service.Impl;

import com.spzx.channel.service.ICategoryService;
import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.domain.R;
import com.spzx.product.api.RemoteCategoryService;
import com.spzx.product.api.domain.vo.CategoryVo;
import jakarta.servlet.ServletException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * projectName: spzx-parent
 *
 * @author: 王宝贵
 * time: 2024/10/8 21:01 周二
 * description:
 */
@Service
public class CategoryServiceImpl implements ICategoryService {

    @Autowired
    private RemoteCategoryService remoteCategoryService;

    /**
     * 用户的分类查询
     * @return 返回集合
     */
    @Override
    public List<CategoryVo> tree() throws ServletException {
        R<List<CategoryVo>> tree = remoteCategoryService.tree(SecurityConstants.INNER);
        //如果异常
        if(tree.getCode() ==R.FAIL){
            throw new ServletException(tree.getMsg());
        }
        return tree.getData();
    }
}